package com.minglead.springboot.platform.sys.service;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.minglead.springboot.common.crud.CrudService;
import com.minglead.springboot.common.utils.CacheUtils;
import com.minglead.springboot.platform.sys.dao.DictDao;
import com.minglead.springboot.platform.sys.entity.Dict;
import com.minglead.springboot.platform.sys.utils.DictUtils;



/**
 * 字典Service
 */
@Service
@Transactional(readOnly = true)
public class DictService extends CrudService<DictDao, Dict> {
	
	/**
	 * 查询字段类型列表
	 * @return
	 */
	public List<String> findTypeList(){
		return dao.findTypeList(new Dict());
	}

	@Transactional(readOnly = false)
	public void save(Dict dict) {
		super.save(dict);
		CacheUtils.remove(DictUtils.CACHE_DICT_MAP);
	}

	@SuppressWarnings("deprecation")
	@Transactional(readOnly = false)
	public void delete(String id) {
		dao.delete(id);
		CacheUtils.remove(DictUtils.CACHE_DICT_MAP);
	}
	
	public Dict getEntityByTypeAndValue(String type,String value){
		return dao.getEntityByTypeAndValue(type, value);
	}
	
	/**
	 * 根据type和label查询字典表，label为模糊查询
	 * @param type
	 * @param label
	 * @return
	 */
	public List<Dict> getEntityListByTypeAndLabel(String type,String label){
		Dict d = new Dict();
		d.setType(type);
		d.setLabel(label);
		return dao.findList(d);
	}
	

}
